package com.example.sample.activity;

import android.app.Activity;
import android.content.Context;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.app.BaseActivity;
import com.example.sample.R;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class HListViewActivity extends BaseActivity {
	
	public static class HListHolder extends RecyclerView.ViewHolder{

		public HListHolder(View arg0) {
			super(arg0);
		}
		
		public TextView text;
		public ImageView image;
	}
	
	public class HAdapter extends RecyclerView.Adapter<HListHolder>{

		@Override
		public int getItemCount() {
			return 15;
		}

		@Override
		public void onBindViewHolder(HListHolder holder, int position) {
			holder.text.setText("第"+(position)+"项");
		}

		@Override
		public HListHolder onCreateViewHolder(ViewGroup viewGroup, int arg1) {
			String infService = Context.LAYOUT_INFLATER_SERVICE;
			LayoutInflater li;
			li = (LayoutInflater)HListViewActivity.this.getSystemService(infService);
			View v = li.inflate(R.layout.item_hlist, viewGroup, false);

			HListHolder holder = new HListHolder(v);
			holder.image = (ImageView)v.findViewById(R.id.idImage);
			holder.text = (TextView)v.findViewById(R.id.idText);
			return holder;
		}
		
	}

	private RecyclerView mHList;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		//mHList = new RecyclerView(this);
		setContentView(R.layout.activity_hlist);
		mHList = (RecyclerView)findViewById(R.id.hList);

		//设置布局管理器   
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);  
        mHList.setLayoutManager(linearLayoutManager);
        mHList.addItemDecoration(new RecyclerView.ItemDecoration() {
        	@Override
        	public void getItemOffsets(Rect outRect, View view,
        			RecyclerView parent, RecyclerView.State state) {
        		// TODO Auto-generated method stub
        		//super.getItemOffsets(outRect, view, parent, state);
        		outRect.set(0, 0, 100, 0);
        	}
		});
		
		HAdapter adapter = new HAdapter();
		mHList.setAdapter(adapter);
		adapter.notifyDataSetChanged();
	}
	
	
	
}
